package leetcode_acm.stackAndQueue;

import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Stack;

/**
 * 功能描述
 *
 * @author: 张庭杰
 * @date: 2023年03月22日 16:29
 */
public class MinStack {
    private final Stack<Integer> min;
    private final Stack<Integer> in;

    public MinStack(){
        min = new Stack<>();
        in = new Stack<>();
    }

    public void push(int val) {
        if(min.isEmpty() || val <= min.peek()){
            min.push(val);
        }
        in.push(val);
    }

    public void pop() {
        if(in.isEmpty()){
            return;
        }
        int val = in.pop();
        if(val == min.peek()){
            min.pop();
        }
    }

    public int top() {
        if(in.isEmpty()){
            return -1;
        }
        return in.peek();
    }

    public int getMin() {
        return min.peek();
    }

}
